<template>
  <!-- 一线城市经验与薪资饼图 -->
  <div class="barChart"></div>
</template>

<script>
import { getXueliRate } from "@/api/page2Api";
export default {
  name: "",
  data() {
    return {
      data: [],
    };
  },
  props: {
    xData: Array,
  },
  watch: {
    xData(newValue) {
      // console.log(newValue,'11')
      this.setChart();
    },
  },
  methods: {
    setChart() {
      let option = {
        title: {
          text: "全国不同学历在招岗位分布情况",
          left: "center",
          textStyle: {
            color: '#fff'
          }
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
          textStyle: {
            color: '#fff'
          }
        },
        series: [
          {
            type: "pie",
            radius: "50%",
            data: this.xData,
            // bottom: 0,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      let myChart = this.$echarts(this.$el);

      myChart.clear();
      myChart.resize();
      myChart.setOption(option);
    },
  },
  mounted() {
    getXueliRate().then((res1) => {
      let res = res1.data;
      if (res.length > 0) {
        this.data = res.map((item) => ({
          name: item.xueli,
          value: item.count,
        }));
        this.setChart();
      }
    });
  },
};
</script>

<style lang="less" scoped>
.barChart {
  width: 100%;
  height: 100%;
}
</style>